/*
    dialog by xlsu
*/
;(function(){
    var template = '<div class="dialog"><div class="dialog-content"><p>&msg&</p><div class="dialog-button"><p>&buttontext&</p></div></div></div>';
    var defaultSetting = {
        msg:"xxxxxx",
        buttontext:"确认",
        callback:function(){}
    }

    var extend = function(obj1,obj2){
        var obj3 =  {};
        for(obj in obj1){obj3[obj] = obj1[obj]}
        for(obj in obj2){obj3[obj] = obj2[obj]}
        return obj3;
    }

    var dialog = function(option){
        var seting = extend(defaultSetting,option);
        this.dialogEle = document.createElement("div");
        this.dialogEle.classList.add("dialog");
        this.dialogEle.innerHTML = template.replace("&msg&",seting.msg).replace("&buttontext&",seting.buttontext);
        document.body.appendChild(this.dialogEle);
        this.dialogEle.querySelector(".dialog-button p").addEventListener("click",function(){
                seting.callback && seting.callback();
        },false);
        this.dialogEle.addEventListener("touchmove",function(event){return false;},false);
        var _this = this;
        this.close = function(){
            document.body.removeChild( _this.dialogEle);
        }
        return this;
    }

    window.xici = window.xici || {};
    window.xici.dialog = dialog;
})()